package scan.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import scan.mapper.ShopMapper;
import scan.po.AdressPO;


import java.net.UnknownHostException;


@Controller
public class TestController {
    @Autowired
    private ShopMapper shopMapper;

    @RequestMapping("find")
    public PageInfo test(Long pagenum,Long pagesize) throws UnknownHostException, InterruptedException {
        if(pagenum==null)
            pagenum=1L;
        if(pagesize==null)
            pagesize=100L;
        PageHelper.startPage(pagenum.intValue(), pagesize.intValue());
        PageInfo<AdressPO> pageInfo = new PageInfo<>(shopMapper.find());
        return pageInfo;
    }

    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String hello(Model model,Long pagenum,Long pagesize) {
        if(pagenum==null || pagenum<=0)
            pagenum=1L;
        if(pagesize==null)
            pagesize=50L;
        PageHelper.startPage(pagenum.intValue(), pagesize.intValue());
        PageInfo<AdressPO> pageInfo = new PageInfo<>(shopMapper.find());
        model.addAttribute("data", pageInfo);
        return "login";
    }
}
